import { getDictionaryList, getOrgAllList, getRoleList, getUnitData, getUserAllList, getprojectList } from '@/views/science/api/common';

const technicalNorms: any = {
  namespaced: true,
  state: {
    rowId: '',
    methodRowId:'',

    unitSelet:[],   //登录人下单位信息
    usersSelet:[], // 登录人下人员信息

    levelNameSelect: [], //标准级别
    authorSelect:[],  //编制类别
    classTypeSelect: [],  //高端研发平台-建设方式
    stateSelect: [], //平台状态
    ptRoleList: [], //成员角色
    fileTypeList: [], //文件类型
    gdlevelSelect: [], //高端研发平台-平台级别
    gjconstructSelect: [],  //国际科技合作基地-建设方式
    jdLevelSelect: [],  //基地级别
    kjlevelSelect: [],//科技转移转化平台-平台级别
    typeSelect: [],  //专业级别
    kjtypeSelect:[],//科技转移转化平台-专业类别

    levelSelect: [], //平台级别
    xtcxTypeSelect:[],// 协同创新平台-专业级别
    classSelect: [], //平台类别
    zyClassSelect: [],//专业类别
    ptRoleSelect: [],//平台成员的平台角色
    projectStateSelect: [], // 项目状态
    projectSelect: [], // 项目来源

    roleList: [], //角色列表
    userAllList: [], //全部人员
    orgAllList: [], //全部机构单位

    sexList: [], //性别
    cooperateList: [], //合作方式


    form: {
			id: "",
			code: "",
			name: "",
			version: "",
			levelId: "",
			levelName: "",
			classId: "",
			classType: "",
			className: "",
			currentStage: "",
			businessId: "",
			business: "",
			mainUnit:"" ,
			publicDate: "",
			enterpriseRanking: "",
			editConditionId: "",
			editCondition: "",
			projectApprovalDate:"",
			effectDate: "",
			failureDate: "",
			startDate: "",
			endDate: "",
			undertakeUnitId: "",
			undertakeUnit: "",
			projectChanger: "",
			projectChangerName: "",
			contactId: "",
			contact: "",
			managerUnit: "",
			renameUnitId: "",
      project:"",
      projectId:"",

      renameUnit: "",
			renameRank: "",
			major: "",
			checkRequirement: "",
			mainWorkContent: "",
		  intro: "",
      unitType: "",
      contactPersonId: "",
      contactPhone: "",
      memberId: "",
    },
    //
    chiefUnits:{
      id: "", //编号Id
      memberId: "", //单位id
      memberName: null, //单位名称
      memberType: null,
      unitType: "", //单位类型
      unitId: null,
      unit: null,
      delFlag: null,
      createUsername: null,
      createBy: null,
      modifyUsername: null,
      modifyBy: null,
      modifyTime: null,
      sort: 1, //排名
      contactPersonId: "", //联系人
      contactPhone: "", //联系方式
      sex: null,
      professionalPost: null,
      pid: null,
      proleId: null,
      prole: null,
      ptype: null
    },
    participatingUnits:{
      id:"",
      renameUnit: "",
			renameRank: "",
			major: "",
			checkRequirement: "",
			mainWorkContent: "",
		  intro: "",
      unitType: "",
      contactPersonId: "",
      contactPhone: "",
      memberId: "",

    },

    files:{
      id:'',
      filePath: "",
      fileType: "",
      fileSize: "",
      fileName: "",
      delFlag: "",
      createUsername: "",
      createBy: "",
      modifyTime: "",
      pid: "",
      ptype: "",
    },

    // 技术工法
    methodForm:{
      id: "", //编号id
      constructionNumber: "", //工法编号
      constructionName: "", //工法名称
      contractUnitId: "", //联系单位id
      contractUnit: "", //联系单位
      contractId: "", //联系人id
      contract: "", //联系人
      enterpriseRankingId: "", //企业排名id
      enterpriseRanking: "", //企业排名
      editConditionId: "", //参编情况id
      editCondition: "", //参编情况
      publicUnit: "", //发布单位
      publicDate: "", //发布时间
      themeWord: "", //主题词
      completeUnitIds: ",", //完成单位id
      completeUnits: "", //完成单位
      mainCompletePersonIds: "", //主要完成人id
      mainCompletePersons: "", //主要完成人
      trdContentIntroduce: "", //工法内容简介
      remark: "", //备注
      trdLevelId: "", //工法级别id
      trdLevel: "", //工单级别
      trdClassId: "", //工法类别id
      trdClass: "", //工法类别
    },

    innovateForm: {
      id:'',
      name: "",
      abbreviation: '',
      code: '',
      unitName: '',
      unitId: '',
      manager: '',
      managerId: "",
      managerTel: '',
      level: '',
      levelId: '',
      subject: '',
      subjectId: '',
      construct: "",
      constructId: '',
      identifyOrg: '',
      identifyDate: '',
      briefIntroduction: ''
    },

    cooperationForm: {
      id:'',
      name: '',
      code: '',
      buildUnit: "",
      buildUnitId: "",
      manager: '',
      managerId: "",
      managerTel: '',
      level: '',
      levelId: '',
      subject: '',
      subjectId: '',
      construct: '',
      constructId: "",
      identifyOrg: '',
      identifyDate: '',
      baseStatus: '',
      baseStatusId: '',
      briefIntroduction: '',
    },

    transferForm: {
      id:'',
      name: '',
      code: '',
      buildUnit: "",
      buildUnitId: "",
      manager: '',
      managerId: "",
      managerTel: '',
      level: '',
      levelId: '',
      subjectClass: '',
      subjectClassId: '',
      identifyOrg: '',
      identifyDate: '',
      baseStatus: '',
      baseStatusId: '',
      briefIntroduction: '',
    },


    gjhProjectLevel:[], //项目级别类别
    gjhLevelSelect:[], // 国际化交流合作-级别-类别
    gjhInteractSelect:[], // 合作方式
    gjhStatueSelect:[], // 项目状态
    gjhInterflowType:[], // 交流类别
    gjhMeetingType:[], //会议类别
    gjhShapeSelect:[], // 参与形式

    technologyProjectsInfo: {
      id: '',
      name: '',
      cooperationMode: '',
      cooperationModeId: '',
      buildUnit: '',
      buildUnitId: '',
      chargePerson: '',
      chargePersonId: '',
      projectLevel: '',
      projectLevelId: '',
      projectClass: '',
      projectClassId: '',
      totalBudget: '',
      approveExternalFund: '',
      partnerContactUnit: '',
      partnerContactPerson: '',
      partnerContactTel: '',
      projectState: '',
      projectStateId: '',
      approvalDate: '',
      shortIntroduction: '',
      expectedAchieve: '',
      remark: ''
    },

    talentInfo: {
      id: '',
      userName: '',
      userId: '',
      sex: '',
      unit: '',
      unitId: '',
      communicateClass: '',
      communicateClassId: '',
      communicateDate:'',
      communicateStyle: '',
      communicateStyleId: '',
      detailInfo: '',
      remark: '',
    },

    meetingInfo: {
      name: '',
      mettingTime: '',
      className: '',
      classId: '',
      joinMethod: '',
      joinMethodId: '',
      unitName:'',
      unitId:'',
      contractUser:'',
      contractUserId:'',
      contractMethod:"",
      reportTitle: '',
      joinPersons: '',
      joinPersonIds: '',
      remark: ''
    }
  },
  mutations: {
    getRowId(state: any, id) {
      state.rowId = id;
    },

    getMethodRowId(state: any, id) {
      state.methodRowId = id;
    },

    emptyForm(state: any) {
      Object.keys(state.form).forEach((key) => {
        state.form[key] = '';
      })
    },

    emptyMethodForm(state: any) {
        Object.keys(state.methodForm).forEach((key) => {
        state.methodForm[key] = '';
      })
    },

    emptyinnovateForm(state: any) {
      Object.keys(state.innovateForm).forEach((key) => {
        state.innovateForm[key] = '';
      })
    },

    emptycooperationForm(state: any) {
      Object.keys(state.cooperationForm).forEach((key) => {
        state.cooperationForm[key] = '';
      })
    },

    emptytransferForm(state: any) {
      Object.keys(state.transferForm).forEach((key) => {
        state.transferForm[key] = '';
      })
    },


    emptytechnologyProjectsInfo(state: any) {
      Object.keys(state.technologyProjectsInfo).forEach((key) => {
        state.technologyProjectsInfo[key] = '';
      })
    },

    emptytalentInfo(state: any) {
      Object.keys(state.talentInfo).forEach((key) => {
        state.talentInfo[key] = '';
      })
    },

    emptymeetingInfo(state: any) {
      Object.keys(state.meetingInfo).forEach((key) => {
        state.meetingInfo[key] = '';
      })
    },

    getForm(state: any, data) {
      const arr1 = Object.keys(data)
      const list = state.form
      for (const key in list) {
        if (arr1.indexOf(key) !== -1) {
          list[key] = data[key]
        }
      }
      state.form = { ...list };
    },
    
    getMethodForm(state: any, data) {
      const arr1 = Object.keys(data)
      const list = state.methodForm
      for (const key in list) {
        if (arr1.indexOf(key) !== -1) {
          list[key] = data[key]
        }
      }
      state.methodForm = { ...list };

    },





    getinnovateForm(state: any, data) {
      const arr1 = Object.keys(data)
      const list = state.innovateForm
      for (const key in list) {
        if (arr1.indexOf(key) !== -1) {
          list[key] = data[key]
        }
      }
      state.innovateForm = { ...list };
    },

    getcooperationForm(state: any, data) {
      const arr1 = Object.keys(data)
      const list = state.cooperationForm
      for (const key in list) {
        if (arr1.indexOf(key) !== -1) {
          list[key] = data[key]
        }
      }
      state.cooperationForm = { ...list };
    },

    gettransferForm(state: any, data) {
      const arr1 = Object.keys(data)
      const list = state.transferForm
      for (const key in list) {
        if (arr1.indexOf(key) !== -1) {
          list[key] = data[key]
        }
      }
      state.transferForm = { ...list };
    },


    gettechnologyProjectsInfo(state: any, data) {
      if(data){
        const arr1 = Object.keys(data)
        const list = state.technologyProjectsInfo
        for (const key in list) {
          if (arr1.indexOf(key) !== -1) {
            list[key] = data[key]
          }
        }
        state.technologyProjectsInfo = { ...list };
      }
    },

    gettalentInfo(state: any, data) {
      const arr1 = Object.keys(data)
      const list = state.talentInfo
      for (const key in list) {
        if (arr1.indexOf(key) !== -1) {
          list[key] = data[key]
        }
      }
      state.talentInfo = { ...list };
    },

    getmeetingInfo(state: any, data) {
      const arr1 = Object.keys(data)
      const list = state.meetingInfo
      for (const key in list) {
        if (arr1.indexOf(key) !== -1) {
          list[key] = data[key]
        }
      }
      state.meetingInfo = { ...list };
    },

    saveDictionaryList(state: any, listData) {
      console.log(listData,'---==-=-==')

      state.levelNameSelect = listData.KJSL_STANDARD_LEVEL_CATEGORY
      state.authorSelect = listData.KJSL_PREPARATION_CATEGORY
      // state.gdlevelSelect = listData.KJSL_GD_LEVEL
      // state.researchSelect = listData.KJSL_RESEARCH_FIELD
      // state.gdconstructSelect = listData.KJSL_HPLAT_CONSTRUCTION_METHOD
      // state.stateSelect = listData.KJSL_PLATFORM_STATUS
      // state.ptRoleList = listData.KJSL_MEMBER_ROLE
      // state.fileTypeList = listData.KJSL_FILE_TYPE
      // state.levelSelect = listData.KJSL_INNOVATE_PLATFORM_LEVEL
      // state.xtcxTypeSelect = listData.KJSL_INNOVATE_ZY_LEVEL
      // state.gjconstructSelect = listData.KJSL_CONSTRUCTION_METHOD
      // state.jdLevelSelect = listData.KJSL_BASE_LEVEL
      // state.kjlevelSelect = listData.KJSL_PLATFORM_LEVEL
      // state.typeSelect = listData.KJSL_PROFESSIONAL_LEVEL
      // state.kjtypeSelect = listData.KJSL_ZH_TYPE

      // state.gjhProjectLevel = listData.KJSL_PROJECT_LEVEL_CATEGORY
      // state.gjhLevelSelect=listData.KJSL_GJ_LEVEL
      // state.gjhInteractSelect = listData.KJSL_COOPERATION_METHODS
      // state.gjhStatueSelect = listData.KJSL_PROJECT_STATUS
      // state.gjhInterflowType = listData.KJSL_COMMUNICATION_CATEGORY
      // state.gjhMeetingType =listData.KJSL_MEETING_CATEGORY
      // state.gjhShapeSelect = listData.KJSL_FORM_OF_PARTICIPATION1
      // state.sexList = listData.SEX
    },

    saveRoleList(state: any, listData) {
      state.roleList = listData
    },

    saveUserAllList(state: any, listData) {
      state.userAllList = listData
    },

    // saveLevelName(state: any, listData) {
    //   state.levelNameSelect = listData
    // },

    saveUnitList(state: any, listData) {
      state.unitSelet = listData
    },

    saveProjectList(state: any, listData) {
      state.projectSelect = listData
    },

  },
  actions: {
    // 获取单位信息
    async getUnit({ commit, state }: any) {
      const rst = await getUnitData()
      console.log(getUnitData)
      const data = rst.data.data
      commit('saveUnitList', { ...state.unitSelet, ...data })
    },
    // 获取人员信息
    // async getUsers({ commit, state }: any) {
    //   const rst = await getPersonnelData()
    //   const data = rst.data.data
    //   commit('saveUsersList', { ...state.usersSelet, ...data })
    // },

    // 根据字典分类code集合获取字典树
    async getDictionaryList({ commit, state }: any, params) {
      const a = params
      const rst = await getDictionaryList(a)
      // const rst = await getDictByCodeList(a)
      const data = rst.data.data
      commit('saveDictionaryList', { ...data })
    },

    async getProjectList({ commit, state }: any) {
      const rst = await getprojectList()
      const data = rst.data.data
      commit('saveProjectList', { ...data })
    },


    // 获取角色列表
    async getRoleList({ commit, state }: any) {
      const rst = await getRoleList()
      const data = rst.data.data
      commit('saveRoleList', { ...state.roleList, ...data })
    },

    //获取全部人员
    async getUserAllList({ commit, state }: any) {
      const rst = await getUserAllList()
      const data = rst.data.data
      // console.log(data)
      commit('saveUserAllList', { ...state.userAllList, ...data })
    },

    //获取全部机构单位
    async getOrgAllList({ commit, state }: any) {
      const rst = await getOrgAllList()
      const data = rst.data.data
      // console.log(rst)
      commit('saveOrgAllList', { ...state.orgAllList, ...data })
    },
  },
}

export default technicalNorms
